import java.io.*;
import java.util.Date;

import org.xml.sax.*;
import org.xml.sax.helpers.*;

public class SAXSolution extends DefaultHandler {
    int count = 0;

    public void startElement(String uri, String localName,
			     String qName, Attributes atts) {
	/*do some testing here to check if the visited element
	  is 'input'*/
    	if(qName.equals("input")){
    		count++;
    	}
    }

    public static void main(String[] args) {
	//args[0] is the XHTML document
	try {
		Date start = new Date();
	    SAXSolution handler = new SAXSolution();
	    XMLReader reader = XMLReaderFactory.createXMLReader();
	    reader.setContentHandler(handler);
	    reader.parse(args[0]);
	    Date finish = new Date();
	    
	    long finishTime = finish.getTime()-start.getTime();
	    System.out.println("SAXSolution: Number of input elements is "+handler.count);
	    System.out.println("SAXSolution: Time was "+finishTime + "ms");
	}
	catch(Exception e) {
	    System.err.println(e);
	}
    }
}